package com.gw.vip.center.util;

import com.gw.vip.center.constant.VipCenterKey;
import com.gw.vip.center.jwt.TokenInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @author GW
 * @description
 * @since 2022-04-15
 */
public class HttpServletUtil {
    /**
     * 从request的attribute中获取信息
     * @return
     */
    public static TokenInfo getTokenInfo(){
        HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        return  (TokenInfo)request.getAttribute(VipCenterKey.TOKEN_INFO);
    }
}
